import cn.edu.zut.Business.ManagementServices;

import cn.edu.zut.Model.Community;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

@WebServlet(urlPatterns = "/HelloServlet")
public class HelloServlet extends HttpServlet {

    Community person;
    ManagementServices service;

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int id= Integer.parseInt(request.getParameter("id"));
        String name=request.getParameter("name");
        String sex=request.getParameter("sex");
        String tel=request.getParameter("tel");
        float tem= Float.parseFloat(request.getParameter("tem"));
        Date time =new Date();
        int state= Integer.parseInt(request.getParameter("state"));

        person.setId(id);
        person.setName(name);
        person.setSex(sex);
        person.setTel(tel);
        person.setTem(tem);
        person.setTime((java.sql.Date)time);
        person.setState(state);

        service.insert(person);

        PrintWriter out=response.getWriter();
        out.println(id);
        out.println(name);
        out.println(sex);
        out.println(tel);
        out.println(tem);
        out.println(time);
        out.println(state);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out=response.getWriter();
        out.println("From Servlet");
    }

    @Autowired
    public void setService(ManagementServices service){
        this.service=service;
    }
    @Autowired
    public void setPerson(Community person){
        this.person=person;
    }
}
